/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */

package cc.aileron.orm;

import static cc.aileron.orm.G2DaoFindCondition.id;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;

import cc.aileron.junit.runner.guice.GuiceInjectRunner;
import cc.aileron.junit.runner.guice.GuiceInjectRunnerModule;
import cc.aileron.orm.sample.PostgresqlEntity;

import com.google.inject.Inject;

/**
 * 
 * @author Aileron
 */
@RunWith(GuiceInjectRunner.class)
@GuiceInjectRunnerModule(value = TryModule.class, arg = "postgresql-jdbc.properties")
public class TryPostgresql
{
    /**
     * try create
     */
    @Test
    public void create()
    {
        final PostgresqlEntity entity = new PostgresqlEntity();
        entity.content = "test";
        dao.insert(entity);
        assertThat(entity.id, not(0));

        System.out.println(entity.id);

        final PostgresqlEntity result = dao.findOne(id(entity.id));
        assertThat(entity.content, is(result.content));
    }

    /**
     * @param daoManager
     */
    @Inject
    public TryPostgresql(final G2DaoManager daoManager)
    {
        this.dao = daoManager.get(PostgresqlEntity.class);
    }

    private final G2Dao<PostgresqlEntity> dao;
}